#include "eval_expr.h"

int main(int argc, char **argv) 
{
  double res;

  struct rpn_stack *stack_rpn;
  struct eval_expr_param param[1];

  if (argc != 2)
  {
    printf("Usage: %s <math expression>\n", argv[0]);
    exit(EXIT_FAILURE);
  }

  stack_rpn = rpn_stack_allocate(MAX_RPN_LENGTH);

  param->lva = list_variables_allocate(10);
  param->lfu = list_functions_allocate(10);

  list_variables_init_default(param->lva);
  list_functions_init_default(param->lfu);

  eval_expr_shunting_yard(argv[1], param, stack_rpn);

  res = eval_expr_evaluation(param, stack_rpn);
  printf("Result is %f\n", res);

  list_variables_free(param->lva);
  list_functions_free(param->lfu);

  rpn_stack_free(stack_rpn);

  return EXIT_SUCCESS;
}
